//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.example.service;

import cn.hutool.core.date.DateUtil;
import com.example.entity.Activityapplication;
import com.example.mapper.ActivityapplicationMapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Iterator;
import java.util.List;

@Service
public class ActivityapplicationService {
    @Resource
    private ActivityapplicationMapper activityapplicationMapper;

    public ActivityapplicationService() {
    }

    public void add(Activityapplication activityapplication) { //管理员不需要注册只需要新增，只有管理员才能增加管理员
        this.activityapplicationMapper.insert(activityapplication);
    }

    public void updateById(Activityapplication activityapplication) {
        this.activityapplicationMapper.updateById(activityapplication);
    }

    public void deleteById(Integer id) {
        this.activityapplicationMapper.deleteById(id);
    }

    public void deleteBatch(List<Integer> ids) {
        Iterator var2 = ids.iterator();

        while(var2.hasNext()) {
            Integer id = (Integer)var2.next();
            this.deleteById(id);
        }

    }

    public Activityapplication selectById(Integer id) {
        return this.activityapplicationMapper.selectById(id);
    }

    public List<Activityapplication> selectAll(Activityapplication activityapplication) {
        return this.activityapplicationMapper.selectAll(activityapplication);
    }

    public List<Activityapplication> selectList(Activityapplication activityapplication) {
        System.out.println(activityapplication);
        return null;
    }

    public PageInfo<Activityapplication> selectPage(Activityapplication activityapplication, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        List<Activityapplication> list = this.activityapplicationMapper.selectAll(activityapplication);
        return PageInfo.of(list);
    }

    /**
     * 根据活动ID查询报名列表
     * @param activityId 活动ID
     * @return 报名列表
     */
    public List<Activityapplication> selectByActivityId(Integer activityId) {
        return this.activityapplicationMapper.selectByActivityId(activityId);
    }

    /**
     * 更新报名状态
     * @param activityapplication 报名信息
     */
    public void updateStatus(Activityapplication activityapplication) {
        this.activityapplicationMapper.updateStatus(activityapplication);
    }

    /**
     * 检查学生是否已报名某个活动
     * @param activityId 活动ID
     * @param studentId 学生ID
     * @return 报名记录（如果存在），否则返回 null
     */
    public Activityapplication checkApplicationExistsForActivity(Integer activityId, Integer studentId) {
        return this.activityapplicationMapper.checkApplicationExistsForActivity(activityId, studentId);
    }
}
